import express from 'express';
import { aiAssessmentController } from '../controllers/aiAssessmentController';
import { roleAuth } from '../middleware/roleAuth';
import { Role } from '@prisma/client';
import { validateRequest } from '../middleware/validation';
import { z } from 'zod';

const router = express.Router();

// 验证Schema
const submissionIdSchema = z.object({
  params: z.object({
    submissionId: z.string().uuid('无效的提交ID')
  })
});

const batchAssessmentSchema = z.object({
  body: z.object({
    submissionIds: z.array(z.string().uuid('无效的提交ID')).min(1, '至少需要一个提交ID')
  })
});

const reassessmentSchema = z.object({
  params: z.object({
    submissionId: z.string().uuid('无效的提交ID')
  }),
  body: z.object({
    teacherFeedback: z.string().optional()
  })
});

// 单个提交的AI评估路由
router.post(
  '/:submissionId/assess',
  roleAuth([Role.ADMIN, Role.TEACHER]),
  validateRequest(submissionIdSchema),
  aiAssessmentController.assessSubmission
);

// 批量评估路由
router.post(
  '/batch-assess',
  roleAuth([Role.ADMIN, Role.TEACHER]),
  validateRequest(batchAssessmentSchema),
  aiAssessmentController.batchAssessSubmissions
);

// 重新评估路由
router.post(
  '/:submissionId/reassess',
  roleAuth([Role.ADMIN, Role.TEACHER]),
  validateRequest(reassessmentSchema),
  aiAssessmentController.reassessSubmission
);

// 获取评估历史路由
router.get(
  '/:submissionId/history',
  roleAuth([Role.ADMIN, Role.TEACHER]),
  validateRequest(submissionIdSchema),
  aiAssessmentController.getAssessmentHistory
);

export default router;
